import java.util.Scanner;

public class StudentTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Student[] arr = {//创建对象
                new Student("aa",20,100),
                new Student("bb",22,89),
                new Student("cc",17,98)};//注意标点符号
        System.out.println("学生信息如下");
        ArrayTools.showMsg(arr);//打印结果
        while(true){
            System.out.println("请输入排序选项：1.年龄（升序）2.分数（降序）");
            int option = sc.nextInt();
            switch (option){
                case 1:
                    arr = ArrayTools.scrt(arr, new MyComparator() {
                        @Override
                        public int compare(Student stu1, Student stu2) {
                            return stu1.getAge()-stu2.getAge();
                        }
                    });
                    System.out.println("学生类按年龄升序后为：");
                    ArrayTools.showMsg(arr);
                    break;
                    case 2:
                    arr = ArrayTools.scrt(arr, new MyComparator() {
                        @Override
                        public int compare(Student stu1, Student stu2) {
                            return -(stu1.getScore()-stu2.getScore());
                        }
                    });
                    System.out.println("学生类按分数降序后为：");
                    ArrayTools.showMsg(arr);
                    break;
                default:
                    System.out.println("输入错误");
                    break;
                }

            }
        }
    }
